package tenantchannellogic

import (
	"context"
	model "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/model/tenant/channel"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/pkg/xerrors"

	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type WavepayInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewWavepayInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WavepayInfoLogic {
	return &WavepayInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *WavepayInfoLogic) WavepayInfo(in *rpc.WavepayInfoRequest) (*rpc.WavepayInfoResponse, error) {
	var CommonResp rpc.CommonResp

	wavepayModel := model.NewTenantChannelWavepayModel(l.ctx, l.svcCtx.Db)
	wavepay, err := wavepayModel.GetWavepayById(in.Id)
	if err != nil {
		CommonResp.Code = xerrors.DBError
		CommonResp.Message = "Wavepay not found"
		return &rpc.WavepayInfoResponse{
			CommonResp: &CommonResp,
		}, err
	}

	CommonResp.Message = "Success"
	return &rpc.WavepayInfoResponse{
		Id:           wavepay.ID,
		CreatedAt:    wavepay.CreatedAt,
		UpdatedAt:    wavepay.UpdatedAt,
		Code:         wavepay.Code,
		Phone:        wavepay.Phone,
		CardHolder:   wavepay.CardHolder,
		MinAmount:    wavepay.MinAmount,
		MaxAmount:    wavepay.MaxAmount,
		DailyTimes:   wavepay.DailyTimes,
		DailyAmount:  wavepay.DailyAmount,
		RemainTimes:  wavepay.RemainTimes,
		RemainAmount: wavepay.RemainAmount,
		VisionLevel:  wavepay.VisionLevel,
		IsDisplay:    wavepay.IsDisplay,
		CommonResp:   &CommonResp,
	}, nil
}
